<html>
<head><meta charset="utf-8"><title>unreachable_unchecked · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked.html">unreachable_unchecked</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="238085685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked/near/238085685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked.html#238085685">(May 10 2021 at 04:29)</a>:</h4>
<p><code>core::hint::unreachable_unchecked()</code> is detected by MIRI if actually hit, correct? If so, is there any reason this can't be stabilized as <code>const fn</code>? Just asking to make sure I don't submit a PR when there's something obvious.</p>



<a name="238089141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked/near/238089141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matt1992 <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked.html#238089141">(May 10 2021 at 05:29)</a>:</h4>
<p>Probably would be a good idea to wait until <code>panic!</code> is const-usable on stable before const-stabilizing <code>unreachable_unchecked</code></p>



<a name="238089199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked/near/238089199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked.html#238089199">(May 10 2021 at 05:30)</a>:</h4>
<p>Why's that?</p>



<a name="238109590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked/near/238109590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked.html#238109590">(May 10 2021 at 09:14)</a>:</h4>
<p>I guess so that ppl don't abuse it as a panic function without a message?</p>



<a name="238109716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked/near/238109716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked.html#238109716">(May 10 2021 at 09:15)</a>:</h4>
<blockquote>
<p>as a panic function without a message?</p>
</blockquote>
<p>And with UB if called at runtime.</p>



<a name="238112075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked/near/238112075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pointerbender <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked.html#238112075">(May 10 2021 at 09:36)</a>:</h4>
<p><code>std::hint::unreachable_unchecked()</code> does not panic I believe (only its counterpart <code>std::unreachable!()</code> panics).</p>



<a name="238112787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked/near/238112787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked.html#238112787">(May 10 2021 at 09:41)</a>:</h4>
<p>Yeah, I suppose avoiding a possible footgun is a good idea. Thankfully const panic seems close.</p>



<a name="238112872"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked/near/238112872" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked.html#238112872">(May 10 2021 at 09:42)</a>:</h4>
<p>And <span class="user-mention" data-user-id="400735">@Pointerbender</span> this is for CTFE, where MIRI can detect UB and error out</p>



<a name="238115503"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked/near/238115503" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pointerbender <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked.html#238115503">(May 10 2021 at 10:05)</a>:</h4>
<p>Ah <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="238140827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked/near/238140827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked.html#238140827">(May 10 2021 at 13:23)</a>:</h4>
<p><span class="user-mention silent" data-user-id="245610">Jacob Pratt</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/unreachable_unchecked/near/238085685">said</a>:</p>
<blockquote>
<p><code>core::hint::unreachable_unchecked()</code> is detected by MIRI if actually hit, correct? If so, is there any reason this can't be stabilized as <code>const fn</code>? Just asking to make sure I don't submit a PR when there's something obvious.</p>
</blockquote>
<p>you seem to be confusing <a href="https://github.com/rust-lang/miri/">Miri-the-tool</a> with the CTFE engine. :) They share a lot of code but they are not one-and-the-same.</p>



<a name="238140842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked/near/238140842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked.html#238140842">(May 10 2021 at 13:23)</a>:</h4>
<p>CTFE detects some UB but less than Miri, for various reasons.</p>



<a name="238141309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked/near/238141309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked.html#238141309">(May 10 2021 at 13:26)</a>:</h4>
<p>Now that <a href="https://github.com/rust-lang/rfcs/pull/3016">https://github.com/rust-lang/rfcs/pull/3016</a> landed I agree we could const-stabilize <code>unreachable_unchecked</code>, but I also agree it seems wise to const-stabilize panics first.</p>



<a name="238198410"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked/near/238198410" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable_unchecked.html#238198410">(May 10 2021 at 19:28)</a>:</h4>
<p>Huh, did not know they were slightly different. Doesn't affect my question but nice to know regardless!</p>
<p>I guess I'll hold off on a stabilization PR for that until const panics is stabilized on nightly (hopefully soon!). Thanks for the info <span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>